
package com.example.main.Conditional.ConditionalOnClass;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import com.example.main.Conditional.*;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import java.util.List;

@Configuration
public class TestConfig {
    
    @Bean
    @ConditionalOnClass(Test2.class)
    Test2 test2() {
        System.out.println("---------Test2 的class文件存在，将Test2注册到容器中---------");
        return new Test2();
    }
    
    public class Test2 {
    }
    
    public static void main(String[] args) {
        
        // 设置日志级别,去掉我不要的信息
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        List<Logger> loggerList = loggerContext.getLoggerList();
        loggerList.forEach(logger -> {
            logger.setLevel(Level.ERROR);
        });
        
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);
        
    }
}